package com.example.studentknowledgesys.controller;

import com.example.studentknowledgesys.service.PointService;
import com.example.studentknowledgesys.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/points")
public class PointAwardController {
    @Autowired
    private PointService pointService;

    // 奖励积分（根据规则类型）
    @PostMapping("/award")
    public Result awardPointsByRule(
            @RequestBody PointAwardRequest request) {
        pointService.awardPoints(request.getUserId(), request.getRuleType(), request.getDescription());
        return Result.success();
    }

    // 自定义奖励积分
    @PostMapping("/custom-award")
    public Result awardCustomPoints(
            @RequestBody CustomPointAwardRequest request) {
        pointService.awardPoints(request.getUserId(), request.getRuleType(),
                request.getPoints(), request.getDescription());
        return Result.success();
    }

    // 请求对象
    static class PointAwardRequest {
        private Long userId;
        private String ruleType;
        private String description;

        public Long getUserId() {
            return userId;
        }

        public void setUserId(Long userId) {
            this.userId = userId;
        }

        public String getRuleType() {
            return ruleType;
        }

        public void setRuleType(String ruleType) {
            this.ruleType = ruleType;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }
// 省略getter/setter
    }

    static class CustomPointAwardRequest {
        private Long userId;
        private String ruleType;
        private int points;
        private String description;

        public Long getUserId() {
            return userId;
        }

        public void setUserId(Long userId) {
            this.userId = userId;
        }

        public String getRuleType() {
            return ruleType;
        }

        public void setRuleType(String ruleType) {
            this.ruleType = ruleType;
        }

        public int getPoints() {
            return points;
        }

        public void setPoints(int points) {
            this.points = points;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }
// 省略getter/setter
    }
}